<?php
class Application_Model_Login
{
	private $_dbAdapter = null;
 
	public function __construct($dbAdapter = null, $log = null)
	{
		$this->_dbAdapter = $dbAdapter;
	}
 
	public function login($username, $password)
	{
		$auth = Zend_Auth::getInstance();
		$authAdapter = new Zend_Auth_Adapter_DbTable(
			$this->_dbAdapter, 'login', 'login', 'passwd', 'sha1(?)');
		$authAdapter->setIdentity($username);
		$authAdapter->setCredential($password);
		
		$result = $auth->authenticate($authAdapter);
		if($result->isValid())
		{
			return true;
		}
		else
		{
			return false;
		}
	}
 
	public function logout()
	{
		// Get the authentication object
		$auth = Zend_Auth::getInstance();
 
		// Clear the user identity to log out
		$auth->clearIdentity();
	}
}